﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Station.Common.Rejudgment
{
    /// <summary>
    /// 镜头
    /// </summary>
    public class ErrCamera
    {
        public int ID;

        public Point CPos = new Point();
        //public Rectangle FovRect
        //{
        //    get
        //    {
        //        return new Rectangle(CPos.X - 2000, CPos.Y - 1480, 4000, 2960);
        //    }
        //}
        /// <summary>
        /// 镜头图片
        /// </summary>
        public Bitmap CameraImage { get; set; }
        public List<ErrComponent> ErrComponents { get; set; } = new List<ErrComponent>();

        public bool TryAdd(ErrComponent comp)
        {
            RectangleF rect = comp.GetRect();
            foreach (var item in ErrComponents)
            {
                var rect1 = item.GetRect();
                rect = RectangleF.Union(rect, rect1);
            }
            if(rect.Width>4000 || rect.Height>2960)
            {
                return false;
            }
            else
            {
                ErrComponents.Add(comp);
                CPos.X = (int)((rect.Left + rect.Right) / 2);
                CPos.Y = (int)((rect.Top + rect.Bottom) / 2);
                return true;
            }
        }

        public bool SplitImage()
        {
            if (CameraImage == null) 
                return false;
            bool rc = true;
            foreach(var item in ErrComponents)
            {
                rc&=item.SetImage(CameraImage, CPos);
            }
            return rc;
        }
    }
}
